// typeorm 实体
import { Entity, Column, PrimaryGeneratedColumn, ManyToMany, JoinTable, OneToMany, OneToOne } from 'typeorm'
import { Roles } from '../role/roles.entity'
import { Exclude } from 'class-transformer'
import { Logs } from '../logs/logs.entity'
import { Profile } from './profile.entity'
@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ unique: true })
  username: string

  @Column({ default: '' })
  email: string

  @Column()
  @Exclude({ toPlainOnly: true })
  password: string

  @ManyToMany(() => Roles, (roles) => roles.users)
  @JoinTable({ name: 'user_roles' })
  roles: Roles[]

  @OneToMany(() => Logs, (logs) => logs.user)
  logs: Logs[]
  @OneToOne(() => Profile, (profile) => profile.user, { cascade: true })
  profile: Profile
}
